ruby-on-rails-4

Specify a different root path for logged in users without using Devise

故事扮演 提交于 2020-01-17 05:35:20
问题 If the user is logged in, I want users#show to be the route path. Else, the route path should be static_pages#home. Please let me know how I can achieve this without using the Devise gem. 回答1: I think having if/else statements in your routes file isn't right. Think of it as a business logic in your routes files. You business logic should be in your Models (not necessarily an ActiveRecord, just any plain old ruby class would do) or if it better fits in your controller (like in this case) in

Ruby on Rails - Nested Attributes and Automatic object creation

孤街醉人 提交于 2020-01-17 05:12:22
问题 I asked a previous question and this one follows... I have 3 Models: Contract, Addendum and Appointment Contract.rb has_many :addendums accepts_nested_attributes_for :addendums Addendum.rb belongs_to :contract has_many :appointments Appointment.rb belongs_to :addendum When an Addendum is created, some Appointments are created automatically. I made this work adding a function on the Addendum's Controller like this def createNewAppointments appointment = Appointment.new(params[:appointment]);

fix the render with ajax in partial

左心房为你撑大大i 提交于 2020-01-17 03:58:24
问题 I am trying to render in another partial, like this: <% cobran = @detalleco.cobran %> $("#cobran_<%= @detalleco.IdCobranza %>").fadeOut(500, function(){ $(this).remove(); $(".child").remove(); $("#container_cobranza").html("<%=escape_javascript(render(:partial => 'cobranza/cobran', cobranza: cobran))%>"); }); but I get this error: ActionView::Template::Error (undefined local variable or method cobran' for #<#<Class:0xb47692ec>:0x83cb1500> Did you mean? cobran_url): 1: <tr id="cobran_<%=

Getting 'undefined method `to_sym' while migrating while setting up Devise

夙愿已清 提交于 2020-01-17 03:06:07
问题 I am trying to set up Pageflow. Finally I managed to create DBs and install pageflow. I can run rails s but I get Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue. in my browser. Anyway, typing bundle exec rake db:create db:migrate would give me this error: == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! StandardError: An error has occurred, all later migrations canceled:

How to pass url to partial/form?

你说的曾经没有我的故事 提交于 2020-01-17 03:01:09
问题 I would like to pass the url to a form, which is in a partial. However, the current setup generates an error message: SyntaxError in OrganizationsController#new syntax error, unexpected keyword_do, expecting keyword_end ...or(@organization), url="url" do |f| @output_buffer.safe_appe... ... The error highlights the 3rd line of the partial/form which is <%= form_for(@organization), url="url" do |f| %> Two views both use the partial/form, and to this end include: ## View1: <%= render

How to pass url to partial/form?

女生的网名这么多〃 提交于 2020-01-17 03:01:04
问题 I would like to pass the url to a form, which is in a partial. However, the current setup generates an error message: SyntaxError in OrganizationsController#new syntax error, unexpected keyword_do, expecting keyword_end ...or(@organization), url="url" do |f| @output_buffer.safe_appe... ... The error highlights the 3rd line of the partial/form which is <%= form_for(@organization), url="url" do |f| %> Two views both use the partial/form, and to this end include: ## View1: <%= render

Rails 4: select DOM element with dynamically generated id

点点圈 提交于 2020-01-17 02:21:24
问题 In my Rails 4 app, I have the following DOM structure on one of my views: <tr id="post_row_<%= post.id%>"> [...] # Truncated for brivety <td class="cell_content_center post_approval_section"> [...] # Truncated for brivety </td> </tr> I need to update the content of the td with JavaScript. In order to select it, I tried: $('tr#post_row_<%= j post.id %> > td.post_approval_section').html('<%= j render(partial: "calendars/post_approval") %>'); but this gives me an error: Failed to load resource:

Rails 4: select DOM element with dynamically generated id

这一生的挚爱 提交于 2020-01-17 02:21:10
问题 In my Rails 4 app, I have the following DOM structure on one of my views: <tr id="post_row_<%= post.id%>"> [...] # Truncated for brivety <td class="cell_content_center post_approval_section"> [...] # Truncated for brivety </td> </tr> I need to update the content of the td with JavaScript. In order to select it, I tried: $('tr#post_row_<%= j post.id %> > td.post_approval_section').html('<%= j render(partial: "calendars/post_approval") %>'); but this gives me an error: Failed to load resource:

Rails Trying to create a profile after the user has been created

試著忘記壹切 提交于 2020-01-16 20:10:26
问题 I'm trying to figure out how to create a new profile for the user that has just been created, I'm using devise on the User model, and the User model has a one to one relationship with the UserProfile model. Here's what my User Model looks like: class User < ActiveRecord::Base has_and_belongs_to_many :roles belongs_to :batch has_one :user_profile after_create :create_user_profile def create_user_profile self.user_profile.new(:name => 'username') end # Include default devise modules. Others

Not able to edit(update nested model rails 4

断了今生、忘了曾经 提交于 2020-01-16 19:25:09
问题 i am building nested form in rails 4.I every thing works as expected But when i try to edit the page then it edit only parent element here project.Child model question elements are not even display in edit mode my _form.html.erb as <%= nested_form_for (@project) do |f| %> <% if @project.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2> <ul> <% @project.errors.full_messages.each do |message| %> <li><%