Rails 4 - When assigning attributes, you must pass a hash as an argument -


can me figure out why getting following error?

when assigning attributes, must pass hash argument. 

the form:

    <%= form_for([current_user, current_user.suggestions.build]) |f| %>         <%= f.label :category %>:         <%= f.select :category, ['startup', 'cars', 'kids', 'food', 'other'] %> <br>         <%= f.text_area :suggestion %><br>         <%= f.submit 'submit suggestion' %>     <% end %> 

suggestioncontroller:

  def create     @suggestion = current_user.suggestions.create(suggestion_params)   end    private     def suggestion_params       params.require(:suggestion).permit(:suggestion, :category)       redirect_to shirts_path     end 

applicationcontroller:

  helper_method :current_user    private      def current_user       @current_user ||= user.find(session[:user_id]) if session[:user_id]     end 

suggestion_params returning last line of method redirect_to shirts_path, current_user.suggestions.create can't accept because isn't acceptable data.

the redirect should in create method:

def create     @suggestion = current_user.suggestions.create(suggestion_params)     redirect_to shirts_path end  private   def suggestion_params     params.require(:suggestion).permit(:suggestion, :category)   end 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -