ruby on rails - Trying to pass parameters -



ruby on rails - Trying to pass parameters -

i'm trying pass url params rails app (ex: /entries/new?name=asdf

controller:

def new @entry = entry.new(params[:name]) end def create @entry = entry.new(params[:name]) if @entry.save redirect_to @entry, notice: 'entry created.' else render :new end end

private # utilize callbacks share mutual setup or constraints between actions. def set_entry @entry = entry.find(params[:id]) end # never trust parameters scary internet, allow white list through. def entry_params params.require(:entry).permit(:name) end end

form field :

<%= hidden_field_tag :name, params[:name] %>

i'm getting error "when assigning attributes, must pass hash argument."

any ideas?

params hash. params[:name] homecoming string ('asdf' in illustration above). when instantiating entry you're passing string when should passing hash. assuming name attribute on entry model, you'll need this

@entry = entry.new(name: params[:name])

ruby-on-rails ruby-on-rails-4

Comments

Popular posts from this blog

php - How to pass multiple values from url -

database - php search bar when I press submit with nothing in the search bar it shows all the data -

ios - How to load .png images from Documents folder of an app -