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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -