jeudi 28 mai 2015

Sending information from view into controller rails

I'm stacked. Here's my form view for events :

    <%= form_for(@event) do |f| %>
  <div class="form-group">
       <%= f.radio_button :repeat, 'once', checked: true%><br>
           <%= f.label :repeat_once, 'once'%><br>
           <%= f.radio_button :repeat, 'daily'%><br>
           <%=f.label :repeat_daily, 'daily'%><br>
           <%= f.radio_button :repeat, 'weekly'%><br>
           <%= f.label :repeat_weekly, 'weekly'%><br>
        </div>
     <div class="actions">
        <%= f.submit %>
      </div>
    <% end %>

And i have method in controller

def create
    @event = Event.new(event_params)
    @event.user_id = current_user.id

    @event.save

  if @event.repeat = 'daily'
   ////
end
if @event.repeat = 'weekly'
  //////////
end

redirect_to events_url


  //// it's doesn't matter what inside if block

Also my migration:

 def change
        add_column :events, :repeat , :string
  end

The problem is in if block, because ALL OF THEM true every time regardless of my choice in view(for example i choose weekly, but anyway app makes it once and daily ) What wrong with code? Thanks for reading :) Waiting for any idea

Aucun commentaire:

Enregistrer un commentaire