Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: How to determine controller/action in view

This is my form partial:

<%= f.simple_fields_for :photo_attributes, :html => { :multipart => true } do |d| %>     <%= d.label :image, :label => 'Upload logo', :required => false  %>     <%= d.file_field :image, :label => 'Image, :required => false', :style => 'margin-bottom:2px'  %>     <%= d.input :image_url, :label => 'Billed URL', :required => false %> <% end %> 

If the action is edit I want to show this instead:

<%= f.simple_fields_for :photo, :html => { :multipart => true } do |d| %>     <%= d.label :image, :label => 'Upload logo', :required => false  %>     <%= d.file_field :image, :label => 'Image, :required => false', :style => 'margin-bottom:2px'  %>     <%= d.input :image_url, :label => 'Billed URL', :required => false %> <% end %> 

How can i achieve this?

like image 742
Rails beginner Avatar asked Nov 08 '11 15:11

Rails beginner


People also ask

What decides which controller receives which requests in Rails?

I fetched this definition from the official rails guide: A controller's purpose is to receive specific requests for the application. Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions.

What is action controller Rails?

Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action.

What is the Rails action View convention?

1 What is Action View? In Rails, web requests are handled by Action Controller and Action View. Typically, Action Controller is concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response.


1 Answers

current_page?(action: 'edit')

See ActionView::Helpers::UrlHelper#current_page?

Rails also makes the methods controller_path, controller_name, action_name available for use in the view.

like image 143
fny Avatar answered Sep 21 '22 13:09

fny