rails 3.2 NoMethodError undefined method `slice' for nil:NilClass -
i getting error end have no clue how fix it. weird thing is, working before. think after run annotate, broken, not sure. error comes confs.controller index , own methods. rejects this: conf.machine_brand[0,1].upcase nomethoderror [ ] bla bla conf model:
# == schema information # # table name: confs # # id :integer not null, primary key # machine_brand :string(255) # machine_model :string(255) # control_unit_brand :string(255) # control_unit_model :string(255) # tool_axis_x :decimal(, ) # tool_axis_y :decimal(, ) # tool_axis_z :decimal(, ) # rotary_axis_number :integer # linear_axis_number :integer # turning_mode :boolean # milling_mode :boolean # description :text # xml :text # user_id :integer # developer_id :integer # created_at :datetime not null # updated_at :datetime not null # class conf < activerecord::base attr_accessible :linear_axis_number, :control_unit_brand, :control_unit_model, :description, :developer_id, :machine_brand, :machine_model, :milling_mode, :rotary_axis_number, :tool_axis_x, :tool_axis_y, :tool_axis_z, :turning_mode, :user_id, :xml belongs_to :developer, :class_name => 'user', :foreign_key => 'developer_id' belongs_to :receiver, :class_name => 'user', :foreign_key => 'user_id' validates :user_id, presence: true validates :developer_id, presence: true end
this confs.controller:
class confscontroller < applicationcontroller before_filter :signed_in_user, only:[:index, :edit, :update, :destroy] before_filter :developer_user, only: :destroy def new @conf = conf.new end def index @grouped = {} conf.all.each |conf| letter = conf.machine_brand.slice(0,1).upcase @grouped[letter] ||= [] @grouped[letter] << conf end end def show @conf = conf.find(params[:id]) respond_to |format| format.html #index.html.erb format.json { render json: @conf } format.xml { render xml: @conf } end end def own @grouped = {} conf.where(:developer_id => current_user.id).each |conf| letter = conf.machine_brand.slice(0,1).upcase @grouped[letter] ||= [] @grouped[letter] << conf end end def create @conf = conf.new(conf_params) if @conf.save flash[:success] = "new configuration uploaded!" redirect_to conf_show_path else flash[:error] = "there problem!" render 'new' end end def destroy @conf = conf.find(params[:id]).destroy redirect_to conf_show_own_path end def update @conf.update_attributes(params[:conf]) end private def signed_in_user unless signed_in? store_location redirect_to signin_url, notice: "please sign in" end end def admin_user redirect_to(root_path) unless current_user.admin? end def developer_user redirect_to(root_path) unless current_user.developer? end def conf_params params.require(:conf).permit(:xml, :user_id, :developer_id) if params[:conf] end end
and conf.new if wish:
<% provide(:title, 'new configuration')%> <h1> upload new configuration </h1> <div class="row"> <div class="span6 offset3"> <%= form_for @conf, :html => {:multipart => true} |f| %> <%= f.label :machine_brand %> <%= f.text_field :machine_brand %> <%= f.label :machine_model %> <%= f.text_field :machine_model %> <%= f.label :control_unit_brand %> <%= f.text_field :control_unit_brand %> <%= f.label :control_unit_model %> <%= f.text_field :control_unit_model %> <%= f.label :tool_axis_x %> <%= f.text_field :tool_axis_x %> <%= f.label :tool_axis_y %> <%= f.text_field :tool_axis_y %> <%= f.label :tool_axis_z %> <%= f.text_field :tool_axis_z %> <%= f.label :rotary_axis_number %> <%= f.text_field :rotary_axis_number %> <%= f.label :linear_axis_number %> <%= f.text_field :linear_axis_number %> <%= f.label :turning_mode %> <%= f.text_field :turning_mode %> <%= f.label :milling_mode %> <%= f.text_field :milling_mode %> <%= f.label :description %> <%= f.text_field :description %> <%= f.label :xml %> <%= f.text_field :xml %> <%= f.label :client %> <%= f.collection_select :user_id, user.where(:admin => false, :developer => false), :id, :name, options ={:prompt => "select client"}, :class =>"user" %> <%= f.label :me %> <%= f.collection_select :developer_id, user.where(:id => current_user.id), :id, :name, options ={:prompt => "select me"}, :class =>"user" %> <br /> <%= f.submit "upload", class: "btn btn-large btn-primary" %> <% end %> </div> </div>
conf.machine_brand.slice(0,1)
think got error here machine_brand
in controller
letter = params[:machine_brand].to_s.slice(0,1).upcase unless params[:machine_brand].blank?
or
letter = params[:conf][:machine_brand].to_s.slice(0,1).upcase unless params[:machine_brand].blank?
Comments
Post a Comment