This question is so basic that you really need to get a RoR book. (Like
“Agile Development with Rails”. I dont mean that in a bad way. You’re
gonna have a bunch of similar questions while getting you bearings with
RoR, and asking on the RoR lists every time is not a good solution.
The forms work well, but now when I transfer the values form the first
form to the second one, it automatically validates the fields. I don`t
want that. It should validate them when I try to submit the data from
the second form.
What should I do ? Do I need to change some validation in the model?
It seems like the first form sends data to the database using the second
form (beeing wierd), insted of simply sending data to the second form.
What do you mean ‘sending data to the second form’? When a form is
submitted the data goes to a controller action, it cannot go direct to
another form.
Did you have a look (and I mean a work through not just a glance) at
the guides as I suggested? They may make it all more
clear.
It is better not to remove all the context from the mail you are
replying to so that each post makes some sort of sense in case the
threading gets lost, as it does sometimes.
It seems like the first form sends data to the database using the second
form (beeing wierd), insted of simply sending data to the second form.
What do you mean ‘sending data to the second form’? When a form is
submitted the data goes to a controller action, it cannot go direct to
another form.
Did you have a look (and I mean a work through not just a glance) at
the guides as I suggested? They may make it all more
clear.
It is better not to remove all the context from the mail you are
replying to so that each post makes some sort of sense in case the
threading gets lost, as it does sometimes.
Colin
Thank you again for you fast reply. Indeed I started working with some
basic forms and debugging methods. I tried some examples but non works,
yet.
I want something like the simple php function, fill a form then send the
values from the input tags in another form.
So I got a simple register from on the index(site controller) page with
3 text_field, when submitted the values from the text_fields should be
send in the second form(user controller), a bigger register form. Only
when I submit the user controller register form, the values should be
send to the database.
The forms work well, but now when I transfer the values form the first
form to the second one, it automatically validates the fields. I don`t
want that. It should validate them when I try to submit the data from
the second form.
What should I do ? Do I need to change some validation in the model?
I don’t understand what you mean by transferring data from one form to
another, but validation happens when an attempt is made to save to the
database, it is nothing to do with forms (except that often the data
has come from a form). Presumably you are saving the data as you
transfer it, which I gather you do not wish to do. If you look in
development.log you may get a better idea of what is happening.
I also wonder whether you are missing some fundamental concepts of
Rails. Have you worked through some of the guides at http://guides.rubyonrails.org/, particularly Getting Started,
Debugging, and ActiveRecord associations?
Thank you again for you fast reply. Indeed I started working with some
basic forms and debugging methods. I tried some examples but non works,
yet.
I want something like the simple php function, fill a form then send the
values from the input tags in another form.
So I got a simple register from on the index(site controller) page with
3 text_field, when submitted the values from the text_fields should be
send in the second form(user controller), a bigger register form. Only
when I submit the user controller register form, the values should be
send to the database.
Regards
Think I got it.
The user controller:
def register @title = “register”
if param_posted?(:user) @user = User.new(params[:user])
< some code that says: stop running code, onClick submit button continue
code >
if @user.save
@user.connect!(session)
flash[:notice] = ""
redirect_to_forwarding_url
else
@user.clear_password!
end
Sigh… nothing works. I`ll abandone all this.
Hang in there a little longer.
If you want the user to first fill in 3 fields, then proceed to another
form to fill out the rest of the fields it will look something like
this:
(You got the first part working, and the 3 fields are submitted to the
controller, right?)
the controller action that receives those parameters will need to render
a new form, which are then submitted to a second controller action. you
could use the same controller action for both steps, but lets use two
for simplicity.
in the controller:
def register_1 #Receives the first 3 fields @user = User.new(params[:user]) #Now register_1.html are rendered
end
register_1.html must now contain a form looking something like this:
<% form_for(@user, :url => {:action => ‘register_2’}) do |form| %> #Because the user is not saved in step 1, this form must contain hidden
fields with the value of the fields from step_1
<%= form.hidden_field(:name) %> #etc #Put the rest of the fields here, just like in the first form
<% end %>
The second controller action receives the complete user info and saves
the user
def register_2 @user = User.create(params[:user]) #Maybe a flash and a redirect here
end
Rails uses the MVC architecture, so you need to learn how the models,
controllers and views interact before you start getting the hang of it.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.