I’m quite new in ruby.I’m doing simple guestbook. There are feedback
controller and message model with a scaffolding. I made scaffolding for
“message” model for example reasons, but when I send some data via
feedback/index it redirects me to the messages controller’s “create”
action.
- Can you show my mistakes and edit some code for clear work with one
controller. - I want to make form_for function in the partial shorter
here is a feedback controller
class FeedbackController < ApplicationController
layout 'application'
def index
@message = Message.new(params[:id])
@messages = Message.all
end
def show
@message = Message.find(params[:id])
end
def new
@message = Message.new
end
def edit
@message = Message.find(params[:id])
end
def create
@message = Message.create(params[:message])
if @message.save
flash[:notice] = 'Message was successfully created.'
########### I'm sure that problem somewhere here, but I don't know which
string should replace that #########
redirect_to(@message)
else
render :action => "new"
end
end
def update
@message = Message.find(params[:id])
respond_to do |format|
if @message.update_attributes(params[:message])
flash[:notice] = 'Message was successfully updated.'
redirect_to(@message)
else
render :action => "edit"
end
end
end
def destroy
@message = Message.find(params[:id])
@message.destroy
respond_to do |format|
redirect_to(messages_url)
end
end
end
Here is form partial, which render by application layout.(i want to make
form_for shorter and working without 1st argument “:feedback”)
<% form_for(:feedback, @message, :method => 'post', :url => {:action =>
'create', :controller => 'feedback'}, :html => {:class =>
'mycleancssform', :id =>'stylized'}) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :message, 'Message' %><br />
<%= f.text_area (:message, :cols => 53, :rows =>5) %>
</p>
<p>
<%= f.label :firstname, 'Name' %><br />
<span class="small">min 2 chars</span>
<%= f.text_field :firstname %>
</p>
<p>
<%= f.label :secondname, 'SEcondname' %><br />
<span class="small">min 2 chars</span>
<%= f.text_field :secondname %>
</p>
<p>
<%= f.label :email, 'Email' %><br />
<span class="small"></span>
<%= f.text_field :email%>
</p>
<p>
<%= f.label :site, 'Site' %><br />
<span class="small"></span>
<%= f.text_field :site %>
</p>
<p>
<%= f.submit 'Submit' %>
</p>
<div class="spacer"></div>
<% end %>