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

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -