ruby on rails - virtual attributes -


<%= form_for(@membership) |f| %>   <%= f.collection_select :user_id, user.all, :id, :email %>   <%= f.collection_select :role_id, role.all, :id, :name %>   <%= f.submit %> <% end %> 

what i'm trying instead of using select box users, want put text field users email.

<%= form_for(@membership) |f| %>   <%= f.text_field :email %>   <%= f.collection_select :role_id, role.all, :id, :name %>   <%= f.submit %> <% end %> 

membership.rb

belongs_to :user belong_to :role  attr_accessor :email def email  self.user.email if self.user end 

what dont know write in controller make work , attr accessor using thing , email method ok? appreciated.

  def create      @membership = membership.new(params[:membership])      if @membership.save         redirect_to(memberships_url)       else        render :action => "new"   end 

if want update existing users only, you'll have find user email in create action, since membership needs user_id , role_id.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -