Reputation: 2495
I have a users controller with these two methods
def trial_signup
@user = User.new
end
def trial_signup_submit
@user = User.create(params[:user_attributes])
end
my trial_signup.html.erb (simple_form) is in app/views/users
Here is a part of my form
<%= simple_form_for(resource, :as => resource_name, :url => users_trial_signup_submit_path(resource_name)) do |f| %>
in my routes I added these
get 'users/trial_signup', to: 'users#trial_signup'
post 'users/trial_signup_submit', to: 'users#trial_signup_submit'
my form is getting rendered correctly but its not posting correctly. I want it to post to my actions that I just created.
I have devise installed. I have another signup work flow for registering a user but this is a trial signup so I need to find another way.
Why is the form not being able to find my User model resource?
Upvotes: 1
Views: 5335
Reputation: 2353
<%= simple_form_for(@user, :url => users_trial_signup_submit_path(@user)) do |f| %>
You're trying to render a devise form outside of a devise controller, so you don't have initialized resource
nor resource_name
variables.
Probably, you need to change your params in your controller too:
def trial_signup_submit
@user = User.create(params[:user])
end
Although I recommend to do something like that:
def trial_signup_submit
@user = User.new(params[:user])
if @user.save
redirect_to <wherever you want>, notice: <your message>
else
render :trial_signup
end
end
PS: I think you should change your actions to something like new_trial
and create_trial
, if you need something different to defaults new
and create
.
Upvotes: 2