开发者

Rails form submit problem

开发者 https://www.devze.com 2023-02-08 09:14 出处:网络
I\'ve get a little proble开发者_如何学编程m. My controller: def new @company = Company.new @title = \"Create company\"

I've get a little proble开发者_如何学编程m.

My controller:

def new
@company = Company.new
@title = "Create company"
end

def create
@company = Company.new(params[:company])
@company.admin_id = current_user.id
if @company.save
  flash[:success] = "Company created!"
  redirect_to admin_path
else
  @title = "New company"
  render 'new'
end    
end

new.html.erb

<%= debug params[:company] %>

<% form_for @company, :html => { :multipart => true } do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<%= render 'fields', :f => f %>
<div class="actions">
<%= f.submit "Submit company!" %>
</div>
<% end %>

Company.rb model

 validates :name,
:presence => true,
:length => { :maximum => 20 }

 validates_attachment_presence :logo

But after submitting form I've get anyway only one error:

Name can't be blank

Of course I'm filling name and logo fields.

Any ideas? Thanks.


You didn't include your _fields partial, and that's probably where your problem is.
Make sure your inputs have appropriate name attributes.

Try to instantiate your model in console and see if validations really work.
You can try something like this: c = Company.new; c.valid?; c.errors and you'll see your errors hash in console.

0

精彩评论

暂无评论...
验证码 换一张
取 消