Routing is using ID has action and action has ID after submitting a form

Posted by Victor Martins on Stack Overflow See other posts from Stack Overflow or by Victor Martins
Published on 2010-05-14T17:21:07Z Indexed on 2010/05/14 17:24 UTC
Read the original article Hit count: 316

I have a model User that has_one user_profile and a User_Profile belongs_to user

in the User controller I have:

  def personal
    @user = User.find_by_id(params[:id])
    @user_profile = @user.user_profile
    @user_profile ||= @user.build_user_profile
  end

  def update_personal
    @user = User.find_by_id(params[:id])
    if @user.user_profile.update_attributes(params[:user_profile])
      flash[:notice] = "OK"
      redirect_to @user
    else
      flash[:notice] = "Fail"
      render :action => 'update_personal'
    end
  end

In my personal.html.erb view I have:

<% semantic_form_for @user_profile, :url => { :action => "update_personal"} do |form| %>
  <%= form.inputs %>
  <%=  form.buttons %>
<%end%>

And on the rountes I have:

map.resources :users, :member => {
         :personal            => :get,
         :update_personal     => :put
        }

Now the strange thing is that I can do:

users/1/personal 

to see the form but when I submit I get this error:

Unknown action

No action responded to 1.

It's trying to find an action with the name 1.

Can anyone point me out on the right direction?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about routes